/*
 * @Descripttion: GGB
 * @version: 1.0
 * @Author: GGB
 * @Date: 2022-01-23 18:55:53
 * @LastEditors: GGB
 * @LastEditTime: 2022-01-31 13:41:29
 */
/**
 * 将数组转化为对象
 * key->id  value -> obj
 * @param {*} arr 
 * @returns 
 */
export const flattenArr = (arr) => arr.reduce((map, item) => { 
    map[item.id] = item
    return map
}, {})
/**
 * 将对象转化为数组
 * @param {*} obj 
 * @returns 
 */
export const objToArr = (obj) => { 
    return Object.keys(obj).map(key=>obj[key])
}


export const getParentNode = (node, parentClassName) => { 
    let current = node
    while (current !== null) { 
        if (current.classList.contains(parentClassName)) { 
            return current
        }
        current=current.parentNode
    }
    return false
}

// 时间戳转换工具
export const timestampToString = (timestamp) => { 
    const date = new Date(timestamp)
    return date.toLocaleDateString()+' ' +date.toLocaleTimeString()
}